import { Component } from 'react'
import { Router, Route, Switch, Redirect } from 'react-router-dom'
import { Login } from '@/pages/Login'
import { NotFound } from '@/pages/NotFound'
import { history } from '@/utils/history'
import AuthRoute from './components/AuthRouse'
import Layout from '@/pages/Layout'

export default class App extends Component {
  render() {
    return (
      <Router history={history}>
        <Switch>
          <Redirect exact from='/' to='/home'></Redirect>
          <Route path='/login' component={Login}></Route>

          {/* 三种写法 */}
          {/* 第一种 */}
          {/* <Route path='/home' component={Layout}></Route> */}

          {/* 第二种 */}
          {/* <Route path='/home'><Layout></Layout></Route> */}

          {/* 第三种：能够访问 /home，需要有 token 封装 */}
          {/* <AuthRoute path='/home' component={Layout}></AuthRoute> */}
          <AuthRoute path='/home'><Layout></Layout></AuthRoute>

          <Route component={NotFound}></Route>
        </Switch>
      </Router>
    )
  }
}
